<?php
$server = new swoole_websocket_server("0.0.0.0", 9501,SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL);
$key_dir = dirname(dirname(dirname(__DIR__))).'/ssl/';
$server->set(array(
        'work_num'=>4,
        'ssl_cert_file'=>$key_dir.'pub.crt',
        'ssl_key_file'=>$key_dir.'priv.key',
));

$server->on('open', function (swoole_websocket_server $server, $request) {
        $content = '连接建立成功';
        //$server->push($request->fd, $content);
        echo $content;
});

$server->on('message', function (swoole_websocket_server $server, $frame) {
	//服务器接受并发送数据
	$data = $frame->data;
            //推送消息
              var_dump($frame->fd);
              //$server->push($frame->fd, $content);
              foreach ($server->connections as $fd) {
                echo microtime(true)."\r\n";
                $server->push($fd, $data);
             }
});

$server->on('close', function ($ser, $fd) {
    echo "client {$fd} closed\n";
});

$server->start();

//ps -eaf |grep "WebSocket.php" | grep -v "grep"| awk '{print $2}'|xargs kill -9